<?php

	require_once('../inc/fen_fns.php');
	
	sec_session_start();

	$userid = $_GET['userid'];
	
	if (isset($userid)) {
		$formtype = "modify";
		$disabled = "disabled";
	} else {
		$formtype = "add";
	}
	

	
	if(login_check($mysqli, '>', '100') == true) {
		
		$query = $_DB->Query("SELECT
							* from fen_members
							WHERE
							fen_members.id = '$userid'");
		$count = $_DB->GetResultNumber($query);
		

		$faculty_id = $_DB->GetResultValue($query, "0", "faculty_id");
		$department_id = $_DB->GetResultValue($query, "0", "department_id");
		$status = $_DB->GetResultValue($query, "0", "status");
		$access_level = $_DB->GetResultValue($query, "0", "access_level");
		$titr = $_DB->GetResultValue($query, "0", "titr");
		$name = $_DB->GetResultValue($query, "0", "name");
		$surname = $_DB->GetResultValue($query, "0", "surname");
		$username = $_DB->GetResultValue($query, "0", "username");
		$email = $_DB->GetResultValue($query, "0", "email");

		
?>

		<script type="text/javascript">
	$(document).ready(function()
		{
		$(".faculty_id").change(function()
		{
		var id=$(this).val();
		var dataString = 'id='+ id;

		
		
		$.ajax
			({
			type: "POST",
			url: "users/ajaxdepartments.php",
			data: dataString,
			cache: false,
			success: function(html)
			{
			$(".department_id").html(html);
			} 
			});
		});
	});
	</script>
	
<p class="contentMainP">Kullanıcı Bilgileri</p>
			<hr noshade>
			
			<form name="input" action="users/<?php echo $formtype; ?>.php" method="post">
			
			
			<label for="form1">Titr:</label>
			<select class="selectShort" type="text" name="titr" id="titr">
				<option value="Prof. Dr." <?php if ($titr == "Prof. Dr.") { echo "selected"; } ?>>Prof. Dr.</option>
				<option value="Doç. Dr." <?php if ($titr == "Doç. Dr.") { echo "selected"; } ?>>Doç. Dr.</option>
				<option value="Yrd. Doç. Dr." <?php if ($titr == "Yrd. Doç. Dr.") { echo "selected"; } ?>>Yrd. Doç. Dr.</option>
				<option value="Öğr. Gör. Dr." <?php if ($titr == "Öğr. Gör. Dr.") { echo "selected"; } ?>>Öğr. Gör. Dr.</option>
				<option value="Öğr. Gör." <?php if ($titr == "Öğr. Gör.") { echo "selected"; } ?>>Öğr. Gör.</option>
				<option value="Uzm." <?php if ($titr == "Uzm.") { echo "selected"; } ?>>Uzman</option>
				<option value="Okutman" <?php if ($titr == "Okutman") { echo "selected"; } ?>>Okutman</option>
				<option value="Arş. Gör." <?php if ($titr == "Arş. Gör.") { echo "selected"; } ?>>Arş. Gör.</option>

			</select><font color="#ff9600"> *</color><br>
			
			<label for="form1">Adı:</label> <input type="text" id="name2" name="name" value="<?php echo $name; ?>"><font color="#ff9600"> *</color>
			<script type="text/javascript">	var name2 = new LiveValidation('name2'); name2.add( Validate.Presence );</script><br>
			
			<label for="form1">Soyadı:</label> <input type="text" id="surname" name="surname" value="<?php echo $surname; ?>"><font color="#ff9600"> *</color>
			<script type="text/javascript">	var surname = new LiveValidation('surname'); surname.add( Validate.Presence );</script><br>
			
			<label for="form1">Kullanıcı Adı:</label> <input type="text" id="username" name="username" value="<?php echo $username; ?>" <?php echo $disabled; ?>><font color="#ff9600"> *</color>
			<script type="text/javascript">	var username = new LiveValidation('username'); username.add( Validate.Presence );</script><br>
			
			<label for="form1">E-posta Adresi:</label> <input type="text" id="email" name="email" value="<?php echo $email; ?>"><font color="#ff9600"> *</color>
			<script type="text/javascript">	var email = new LiveValidation('email'); email.add( Validate.Presence );</script><br>
			
			<label for="form1">Fakülte:</label>
			<select type="text" name="faculty_id" class="faculty_id">
			<option value="">Seçiniz</option>
			
<?php 
			$query = $_DB->Query("SELECT * from fen_faculty ORDER BY faculty_name ASC");
			$count = $_DB->GetResultNumber($query);

			for ($i=0; $i<$count; $i++)
			{
				if ($faculty_id == $_DB->GetResultValue($query, $i, "id")) {
					$selected = "selected";
				} else {
					$selected = "";
				}
				
				echo "<option value=\"".$_DB->GetResultValue($query, $i, "id")."\" ".$selected.">".$_DB->GetResultValue($query, $i, "faculty_name")."</option>";
			}
?>			
			</select><font color="#ff9600"> *</color><br>
			
			<label for="form1">Bölüm:</label>
			<select type="text" name="department_id" class="department_id">
			
<?php 
			if (!$faculty_id) { echo "<option value=\"\">Seçiniz</option>"; }
			$query = $_DB->Query("SELECT * from fen_department where faculty_id = '".$faculty_id."'ORDER BY department_name ASC");
			$count = $_DB->GetResultNumber($query);

			for ($i=0; $i<$count; $i++)
			{
				if ($department_id == $_DB->GetResultValue($query, $i, "id")) {
					$selected = "selected";
				} else {
					$selected = "";
				}
				
				echo "<option value=\"".$_DB->GetResultValue($query, $i, "id")."\" ".$selected.">".$_DB->GetResultValue($query, $i, "department_name")."</option>";
			}
?>			
			</select><font color="#ff9600"> *</color><br>
			
			<label for="form1">Yetki Seviyesi:</label>
			<select class="selectShort" type="text" name="access_level" id="access_level">
				<option value="10" <?php if ($access_level == "10") { echo "selected"; } ?>>Öğretim Üyesi</option>
				<option value="50" <?php if ($access_level == "50") { echo "selected"; } ?>>Dekanlık</option>
				<option value="60" <?php if ($access_level == "60") { echo "selected"; } ?>>Koordinatörlük</option>
				<option value="70" <?php if ($access_level == "70") { echo "selected"; } ?>>Mali İşler</option>
				<option value="100" <?php if ($access_level == "100") { echo "selected"; } ?>>Rektörlük</option>
			</select><font color="#ff9600"> *</color><br>
			
			<label for="form1">Durum:</label>
			<select class="selectShort" type="text" name="status" id="status">
				<option value="1" <?php if ($status == "1") { echo "selected"; } ?>>Aktif</option>
				<option value="0" <?php if ($status == "0") { echo "selected"; } ?>>Pasif</option>
			</select><font color="#ff9600"> *</color><br>
			
			
			<br>
			
			<script type="text/javascript">
			$(document).ready(function() {
			    $('.buttonClose2').click(function(){
			        $(".contentTopArea").slideToggle();
			    }); 

   			 });
			</script>
			
			<input id="buttonSaveNew" type="submit" value="Kaydet"><a class="buttonClose2" id="buttonClose2">Kapat</a><br><br>
			<input type="hidden" name="user_id" value="<?php echo $userid; ?>">
			</form>

			
<?php 

} else {
	header('Location: ../index.php?error=2');
}

?>